/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.put.dcs.core.utils.serializer.adapters;

import com.thoughtworks.xstream.XStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Logger;
import pl.put.dcs.core.utils.serializer.SerializerInterfejs;

/**
 *
 * @author LukaszR
 */
public class XPathAdapter implements SerializerInterfejs
{
    public static Logger log = Logger.getLogger( XPathAdapter.class.getName() );
    private XStream xStream = new XStream();

    @Override
    public void init()
    {
        this.xStream = new XStream();
    }

    @Override
    public String serializeToString( Object object )
    {
        return this.xStream.toXML( object );
    }

    @Override
    public void serializeToFile( Object object, OutputStream out )
    {
        
        this.xStream.toXML( object, out );
    }

    @Override
    public Object unSerializeFromFile( InputStream in )
    {
        return this.xStream.fromXML( in );
    }

    @Override
    public Object unSerializeFromString( String xml )
    {
        Object ret = null;
        try
        {
            ret = this.xStream.fromXML( xml );
        }
        catch ( Exception e )
        {
            //e.printStackTrace();
            log.warning( e.getMessage() );
            
            return null;
        }
        return ret;
    }
}
